package com.madou.dbtool.mysql.init;

import com.madou.dbtool.common.enums.DBEnum;
import com.madou.dbtool.event.DBEventManager;
import com.madou.dbtool.event.def.event.OpenHtmlEvent;
import com.madou.dbtool.node.RootNodeInitialization;
import com.madou.dbtool.relationship.init.BaseNodeInitialization;
import com.madou.dbtool.relationship.pojo.ConnectionInfo;
import com.madou.dbtool.utils.InputStreamUtils;

import java.io.InputStream;
import java.util.HashMap;

/**
 * 初始化默认的Redis连接
 * @author miukoo
 */
public class MysqlInit extends BaseNodeInitialization implements RootNodeInitialization {

    @Override
    public DBEnum getDBEnumType() {
        return DBEnum.MYSQL;
    }

    @Override
    public HashMap getInitDataSourceMap() {
        HashMap defaultValue = new HashMap<>();
        defaultValue.put("name","localhost:3306");
        defaultValue.put("uri","localhost:3306:root:123456");
        return defaultValue;
    }

    @Override
    public ConnectionInfo getDefaultConnectionInfo() {
        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.setHost("localhost");
        connectionInfo.setPort(3306);
        connectionInfo.setPassword("123456");
        connectionInfo.setUsername("root");
        return connectionInfo;
    }

    @Override
    public String getDataSourceManagerName() {
        return "mysqlDataSourceManager";
    }

    @Override
    public String getDataSourceManagerClass() {
        return "com.madou.dbtool.mysql.manager.MysqlDataSourceManager";
    }


    public void initReadMe(){
        if(!isLoadReadMe) {
//            String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT);
//            if(osName.contains("mac")){
//                super.initReadMe();
//            }else {
                InputStream resourceAsStream = this.getClass().getResourceAsStream("/mysql.html");
                if (resourceAsStream != null) {
                    String temp = null;
                    try {
                        temp = InputStreamUtils.inputStreamTOString(resourceAsStream);
                        DBEventManager.notice(new OpenHtmlEvent(temp, "使用帮助"));
                        isLoadReadMe = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
//            }
        }
    }

}
